﻿@model PagedList<ChangeMeterInfo>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/css/select.css" rel="stylesheet" type="text/css" />
    <link href="/css/frominfostyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script src="/js/jquery.form.js"></script>
    <script type="text/javascript" src="/js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="/js/select-ui.min.js"></script>
    <script language="javascript">
        $(function () {
            //导航切换
            $(".imglist li").click(function () {
                $(".imglist li.selected").removeClass("selected")
                $(this).addClass("selected");
            })
        })
    </script>
    <script type="text/javascript">

        function Search(obj) {
            $form1 = $('#form1');
            var customerId = $form1.find("[name='userId']").val();
            $.post('/user/FindByCustomerId', { customerId: customerId }, function (data) {
                if (data.Succeed) {
                    $form1.find("[name='CustomerName']").val(data.Obj.Name);
                    $form1.find("[name='WaterTypeId']").val(data.Obj.WaterTypeName);
                    $form1.find("[name='MeterNo']").val(data.Obj.MeterNo);
                    $form1.find("[name='FirstArea']").val(data.Obj.FirstArea);
                    $form1.find("[name='SecondArea']").val(data.Obj.SecondArea);
                    $form1.find("[name='DetailAddress']").val(data.Obj.DetailAddress);
                    $form1.find("[name='ParentId']").val(data.Obj.EmployeeName);
                    $form1.find("[name='MeterNature']").val(data.Obj.MeterNature);
                    $form1.find("[name='CreateDate']").val(data.Obj.CreateDate);
                    $form1.find("[name='CustomerId']").val(data.Obj.Id);
                }
                else {
                    window.alert("指定编号的用户不存在！");
                }
            }, 'json')
        }

        function Search1(obj) {
            $form1 = $('#form2');
            var customerId = $form1.find("[name='userId']").val();
            $.post('/user/FindByCustomerId', { customerId: customerId }, function (data) {
                if (data.Succeed) {
                    $form1.find("[name='CustomerName']").val(data.Obj.Name);
                    $form1.find("[name='WaterTypeId']").val(data.Obj.WaterTypeName);
                    $form1.find("[name='MeterNo']").val(data.Obj.MeterNo);
                    $form1.find("[name='FirstArea']").val(data.Obj.FirstArea);
                    $form1.find("[name='SecondArea']").val(data.Obj.SecondArea);
                    $form1.find("[name='DetailAddress']").val(data.Obj.DetailAddress);
                    $form1.find("[name='ParentId']").val(data.Obj.EmployeeName);
                    $form1.find("[name='MeterNature']").val(data.Obj.MeterNature);
                    $form1.find("[name='CreateDate']").val(data.Obj.CreateDate);
                    $form1.find("[name='CustomerId']").val(data.Obj.Id);
                }
                else {
                    window.alert("指定编号的用户不存在！");
                }
            }, 'json')
        }



        $(document).ready(function () {

            var api = {
                edit: "/meter/ChangeMeterEdit",
                del: "/meter/ChangeMeterDel"
            }
            $('#form1').attr('action', api.edit);
            $('#form2').attr('action', api.edit);


            $(".click").click(function () {
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function () {
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function () {
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function () {
                $(".tip").fadeOut(100);
            });

            //用户添加
            $(".clicka").click(function () {
                $(".tipa").fadeIn(200);
            });
            $(".tiptopa a").click(function () {
                $(".tipa").fadeOut(200);
            });

            $(".surea").click(function () {
                $(".tipa").fadeOut(100);
            });


            $(".cancela").click(function () {
                $(".tipa").fadeOut(100);
            });

            //抄表添加
            $(".clickfromchangeadd").click(function () {
                $(".tipfromchangeadd").fadeIn(200);
            });

            $(".tiptopfromchangeadd a").click(function () {
                $(".tipfromchangeadd").fadeOut(200);
            });

            $(".surefromchangeadd").click(function () {

                $('#form1').ajaxSubmit({
                    success: function (data) {
                        if (data.Succeed) {
                            window.location.reload();
                        } else {
                            alert(data.Msg);
                        }
                    }
                })

            });

            $(".cancelfromchangeadd").click(function () {
                $(".tipfromchangeadd").fadeOut(100);
            });


            //抄表修改
            $(".clickfromchangemodify").click(function () {
                var count = $("input:checked").length;
                if (count < 1) {
                    alert("至少选择一项进行修改！");
                }
                else if (count > 1) {
                    alert("只能选择一项进行修改！");
                }
                else {
                    $(".tipfromchangemodify").fadeIn(200);

                    var jsonModel = $("input:checked").parents('tr').attr('jsonModel');
                    var model = $.parseJSON(jsonModel);
                    $('#form2').find("[name='userId']").val(model.Customer.CustomerId).attr("readonly", "readonly");
                    Search1();

                    $('#form2').find("input[name='Id']").val(model.Id);
                    $('#form2').find("input[name='CustomerId']").val(model.Customer.Id); 
                    $('#form2').find("input[name='NewMeterNo']").val(model.NewMeterNo); 
                    $('#form2').find("input[name='MeterStart']").val(model.MeterStart);

                    var date = new Date(model.ChangeMeterDate);
                    var formatDate1 = date.format("yyyy/MM/dd"); 
                    $('#form2').find("select[name='ChangeMeterDate']").find("option[value='" + formatDate1 + "']").attr("selected", true);
                    $('#form2').find("select[name='ChangeMeterDate']").prev().find("em:first").text($('#form2').find("select[name='ChangeMeterDate']").find("option:selected").text());
                     
                    if (model.ProcesDate) { 
                        var date1 = new Date(model.ProcesDate);
                        var formatDate2 = date1.format("yyyy/MM/dd");
                        $('#form2').find("select[name='ProcesDate']").find("option[value='" + model.formatDate2 + "']").attr("selected", true);
                        $('#form2').find("select[name='ProcesDate']").prev().find("em:first").text($('#form2').find("select[name='ProcesDate']").find("option:selected").text());
                    }

             

                }




              



            });

            $(".tiptopfromchangemodify a").click(function () {
                $(".tipfromchangemodify").fadeOut(200);
            });


            $(".surefromchangemodify").click(function () {

                $('#form2').ajaxSubmit({
                    success: function (data) {
                        if (data.Succeed) {
                            window.location.reload();
                        } else {
                            alert(data.Msg);
                        }
                    }
                }) 

            });



            $(".cancelfromchangemodify").click(function () {
                $(".tipfromchangemodify").fadeOut(100);
            });

            //抄表修改
            $(".clickfromchangesearch").click(function () {
                $(".tipfromchangesearch").fadeIn(200);
            });

            $(".tiptopfromchangesearch a").click(function () {
                $(".tipfromchangesearch").fadeOut(200);
            });

            $(".surefromchangesearch").click(function () {
                $(".tipfromchangesearch").fadeOut(100);
            });

            $(".cancelfromchangesearch").click(function () {
                $(".tipfromchangesearch").fadeOut(100);
            });

            //删除用户
            $(".clickdel").click(function (del) {
                $(".tipdel").fadeIn(200);
            });

            $(".tiptopdel a").click(function (del) {
                $(".tipdel").fadeOut(200);
            });

            $(".suredel").click(function (del) { 
                $obj = $("input:checked").parents("tr");
                $.post(api.del, { id: $obj.find("input:checked").val() }, function (data) {
                    $(".tipdel").fadeOut(100);
                    window.location.reload();
                }, 'json')  
            });

            $(".canceldel").click(function (del) {
                $(".tipdel").fadeOut(100);
            });

        });
    </script>
    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 150
            });
        });
    </script>
</head>
<body>
    <div class="place">
        <span>位置：</span>
        <ul class="placeul">
            <li><a href="#">首页</a></li>
            <li><a href="#">抄表管理</a></li>
            <li><a href="#">抄表添加</a></li>
        </ul>
    </div>
    <div class="rightinfo">
        <div class="tools">
            <ul class="toolbar">
                <li class="clickfromchangeadd"><span><img src="/images/t01a.png" /></span>添加</li>
                <li class="clickfromchangemodify"><span><img src="/images/t02.png" /></span>修改</li>
                <li class="clickdel"><span><img src="/images/t03.png" /></span>删除</li>
                <li class="clickfromchangesearch"><span><img src="/images/t10.png" /></span>查询</li>
                <li class="clickfrom"><span><img src="/images/t09.png" /></span>导出</li>
                <li class="click"><span><img src="/images/t08.png" /></span>打印</li>

            </ul>

        </div>
        <table class="imgtable">
            <thead>
                <tr>
                    <th>选择</th>
                    <th>用户编号</th>
                    <th>用户姓名</th>
                    <th>区域分布</th>
                    <th>区域名称</th>
                    <th>详细地址</th>
                    <th>用水类别</th>
                    <th>换表日期</th>
                    <th>旧表编号</th>
                    <th>新表编号</th>
                    <th>换表初值</th>
                    <th>执行日期</th>
                    <th>操作人员</th>
                </tr>
            </thead>
            <tbody>

                @foreach (var item in Model)
                {
                    <tr jsonModel="@(JsonConvert.SerializeObject(item,new JsonSerializerSettings{ReferenceLoopHandling = ReferenceLoopHandling.Ignore}))">
                        <td><input name="" type="checkbox" value="@(item.Id)" /></td>
                        <td>@item.Customer.CustomerId</td>
                        <td height="30px;">@item.Customer.CustomerName</td>
                        <td><a href="#">@item.Customer.FirstArea</a></td>
                        <td>@item.Customer.SecondArea</td>
                        <td>@item.Customer.DetailAddress</td>
                        <td>@item.Customer.WaterType.TypeName</td>
                        <td>@(item.ChangeMeterDate.ToString("yyyy/MM/dd"))</td>
                        <td>@(item.Customer.MeterNo)</td>
                        <td>@(item.NewMeterNo)</td>
                        <td>@(item.MeterStart)</td>
                        <td>@(item.ProcesDate?.ToString("yyyy/MM/dd"))</td>
                        <td>@(item.ManagerInfo.UserName)</td>
                    </tr>

                }

            </tbody>
        </table>
        <div class="pagin">
            <div class="message">共<i class="blue">@(Model.TotalItemCount)</i>条记录，共&nbsp;<i class="blue">@(Model.TotalPageCount)&nbsp;</i>页</div>
            @Html.Pager(Model, BaseController.PagerOptions)
        </div>
        <form id="form1" method="post">
            <!--换表添加-->
            <div class="tipfromchangeadd">
                <div class="tiptopfromchangeadd"><img src="/images/t06.png" /><span>换表添加</span><a></a></div>
                <div class="tipinfofromchangeadd">
                    <div class="userinfozbfromchangeadd">
                        <dt class="userinfozbtitfromchangeadd">用户信息</dt>
                        <ul class="seachform">
                            <li>
                                <label>用户编号</label>
                                <input name="userId" type="text" class="scinput" onblur="Search()" />
                            </li>
                            <li>
                                <label>用户姓名</label>
                                <input name="CustomerName" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>用水类型</label>
                                <input name="WaterTypeId" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>水表编号</label>
                                <input name="MeterNo" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                            <li>
                                <label>区域分布</label>
                                <input name="FirstArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>区域名称</label>
                                <input name="SecondArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>详细地址</label>
                                <input name="DetailAddress" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                        </ul>
                    </div>
                    <div class="tiprightfromchangeadd">
                        <dt class="userinfotitfromchangeadd">新表信息</dt>
                        <ul class="seachform">
                            <li>
                                <label>新表编号</label>
                                <input name="NewMeterNo" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>换表日期</label>
                                <div class="vocation">

                                    <select class="select3" name="ChangeMeterDate">

                                        @{
                                            var dateStart1 = DateTime.Now.AddDays(-DateTime.Now.Day).AddDays(1);
                                            var dateEnd1 = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);
                                            var tempDate1 = dateStart1;
                                        }
                                        @while (tempDate1 >= dateStart1 && tempDate1 <= dateEnd1)
                                        {
                                            <option value="@(tempDate1.ToString("yyyy/MM/dd"))">@tempDate1.ToString("yyyy年MM月dd日")</option>
                                            tempDate1 = tempDate1.AddDays(1);
                                        }


                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>换表初值</label>
                                <input name="MeterStart" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>执行日期</label>
                                <div class="vocation">
                                    <select class="select3" name="ProcesDate">
                                        @{
                                            var dateStart2 = DateTime.Now.AddDays(-DateTime.Now.Day).AddDays(1);
                                            var dateEnd2 = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);
                                            var tempDate2 = dateStart2;
                                        }
                                        @while (tempDate2 >= dateStart2 && tempDate2 <= dateEnd2)
                                        {
                                            <option value="@(tempDate2.ToString("yyyy/MM/dd"))">@tempDate2.ToString("yyyy年MM月dd日")</option>
                                            tempDate2 = tempDate2.AddDays(1);
                                        }

                                    </select>
                                </div>
                                <label>&nbsp;<font color="ff0000">(抄表按新表初值执行)</font></label>
                            </li>

                        </ul>
                    </div>
                </div>
                <div class="tipbtnfromchangeadd">
                    @Html.Hidden("CustomerId", "")
                    <input name="" type="button" class="surefromchangeadd" value="添加" />
                    &nbsp;
                    <input name="" type="button" class="cancelfromchangeadd" value="取消" />
                </div>
            </div>
        </form>



        <!--删除用户-->
        <div class="tipdel">
            <div class="tiptopdel"><span>提示信息</span><a></a></div>
            <div class="tipinfodel">
                <span><img src="/images/ticon01.png" /></span>
                <div class="tiprightdel">
                    <p>确定要删除用户的记录吗？</p>
                    <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
                </div>
            </div>
            <div class="tipbtndel">
                <input name="" type="button" class="suredel" value="确定" />
                &nbsp;
                <input name="" type="button" class="canceldel" value="取消" />
            </div>
        </div>

        <!--抄表入库-->
        <div class="tipin">
            <div class="tiptopin"><span>提示信息</span><a></a></div>
            <div class="tipinfoin">
                <span><img src="/images/ticon01.png" /></span>
                <div class="tiprightin">
                    <p>确定要把所选用户的抄表数据加入到抄表总数据中吗？</p>
                    <p>该操作不可逆请慎用？</p>
                    <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
                </div>
            </div>
            <div class="tipbtnin">
                <input name="" type="button" class="surein" value="确定" />
                &nbsp;
                <input name="" type="button" class="cancelin" value="取消" />
            </div>
        </div>

        <form id="form2" method="post">
            <!--换表修改-->
            <div class="tipfromchangemodify">
                <div class="tiptopfromchangemodify"><img src="/images/t06.png" /><span>换表修改</span><a></a></div>
                <div class="tipinfofromchangemodify">
                    <div class="userinfozbfromchangemodify">
                        <dt class="userinfozbtitfromchangemodify">用户信息</dt>
                        <ul class="seachform">
                            <li>
                                <label>用户编号</label>
                                <input name="userId" type="text" class="scinput" onblur="Search()" />
                            </li>
                            <li>
                                <label>用户姓名</label>
                                <input name="CustomerName" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>用水类型</label>
                                <input name="WaterTypeId" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>水表编号</label>
                                <input name="MeterNo" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>

                            <li>
                                <label>区域分布</label>
                                <input name="FirstArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>区域名称</label>
                                <input name="SecondArea" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                            <li>
                                <label>详细地址</label>
                                <input name="DetailAddress" type="text" class="scinput" disabled="disabled" style="background:#EFEFEF" />
                            </li>
                        </ul>
                    </div>
                    <div class="tiprightfromchangemodify">
                        <dt class="userinfotitfromchangemodify">新表信息</dt>
                        <ul class="seachform">
                            <li>
                                <label>新表编号</label>
                                <input name="NewMeterNo" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>换表日期</label>
                                <div class="vocation">

                                    <select class="select3" name="ChangeMeterDate">

                                        @{
                                            var dateStart3 = DateTime.Now.AddDays(-DateTime.Now.Day).AddDays(1);
                                            var dateEnd3 = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);
                                            var tempDate3 = dateStart3;
                                        }
                                        @while (tempDate3 >= dateStart3 && tempDate3 <= dateEnd3)
                                        {
                                            <option value="@(tempDate3.ToString("yyyy/MM/dd"))">@tempDate3.ToString("yyyy年MM月dd日")</option>
                                            tempDate3 = tempDate3.AddDays(1);
                                        }


                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>换表初值</label>
                                <input name="MeterStart" type="text" class="scinput" />
                            </li>
                            <li>
                                <label>执行日期</label>
                                <div class="vocation">
                                    <select class="select3" name="ProcesDate">
                                        @{
                                            var dateStart4 = DateTime.Now.AddDays(-DateTime.Now.Day).AddDays(1);
                                            var dateEnd4 = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);
                                            var tempDate4 = dateStart4;
                                        }
                                        @while (tempDate4 >= dateStart4 && tempDate4 <= dateEnd4)
                                        {
                                            <option value="@(tempDate4.ToString("yyyy/MM/dd"))">@tempDate4.ToString("yyyy年MM月dd日")</option>
                                            tempDate4 = tempDate4.AddDays(1);
                                        }

                                    </select>
                                </div>
                                <label>&nbsp;<font color="ff0000">(抄表按新表初值执行)</font></label>
                            </li>

                        </ul>
                    </div>
                </div>
                <div class="tipbtnfromchangemodify">
                    @Html.Hidden("CustomerId", "")
                    @Html.Hidden("Id","")
                    <input name="" type="button" class="surefromchangemodify" value="确定" />
                    &nbsp;
                    <input name="" type="button" class="cancelfromchangemodify" value="取消" />
                </div>
            </div>

        </form>
         
        <form id="form3" method="get">


            <!--换表查询-->
            <div class="tipfromchangesearch">
                <div class="tiptopfromchangesearch"><img src="/images/t06.png" /><span>换表查询</span><a></a></div>
                <div class="tipinfofromchangesearch">
                    <div class="tiprightfromchangesearch">
                        <dt class="userinfotitfromchangesearch">请输入查询条件</dt>
                        <ul class="seachform">
                            <li>
                                <label>用户编号</label>
                                <input name="CustomerId" type="text" class="scinput"  value="@(ViewBag.CustomerId)"/>
                            </li> 
                        </ul>
                    </div>
                </div>
                <div class="tipbtnfromchangesearch">
                    <input name="" type="submit" class="surefromchangesearch" value="搜索" />
                    &nbsp;
                    <input name="" type="button" class="cancelfromchangesearch" value="取消" />
                </div>
            </div>

        </form>
        <script type="text/javascript">
            $('.tablelist tbody tr:odd').addClass('odd');
        </script>
    </div>
</body>
</html>
